package com._54programer;

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IndexTest1 {

    public static void main(String[] args) throws UnknownHostException {
        //1.连接信息
        InetSocketTransportAddress address = new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300);

        //2.集群名称
        Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();

        //3.es连接客户端
        PreBuiltTransportClient client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(address);

        //4.创建索引
        CreateIndexRequestBuilder indexRequestBuilder = client.admin().indices().prepareCreate("blog1");
        CreateIndexResponse indexResponse = indexRequestBuilder.get();
        System.out.println(indexResponse.index());

        //5.关闭客户端
        client.close();
    }

}
